#include <iostream> 
using namespace std;

class Base{
	private :
		int data;
		Base * next;
	public :
		Base(Base *t){
			data=0;
			next=t;
		}
		Base(int i,Base *t){
			data=i;
			next=t;
		}
		void fun(){
			cout<<"data="<<data<<endl;
			if (next)
				next->fun();
		}
		virtual ~Base (){
		}
		
};

class D1:public Base{
	public :
		//D1(Base *t):Base (t){} 
		D1(int i,Base *t):Base (i,t){}
		~D1(){
			cout <<"D1.des"<<endl;
		}
};

class D2:public Base{
	public :
		//D2(Base *t):Base (t){} 
		D2(int i,Base *t):Base (i,t){}
		~D2(){
			cout <<"D2.des"<<endl;
		}
};

class D3:public Base{
	public :
		//D3(Base *t):Base (t){} 
		D3(int i,Base *t):Base (i,t){}
		~D3(){
			cout <<"D3.des"<<endl;
		}
};

int main(void){//d1 3   d2  4     d3  5
	D3 *pd3=new D3(5,NULL);
	D2 *pd2=new D2(4,pd3);
	Base *pd=new D1(3,pd2);
	
	pd->fun();
	
	delete pd3;
	delete pd2;
	delete pd;
	return 0;
}
